//
//  MYTransferredOutViewController.m
//  投融保
//
//  Created by 523 on 13-12-19.
//  Copyright (c) 2013年 木叶科技. All rights reserved.
//

#import "ApplyTransferredOutVC.h"

#import "MYTransferredoutVC.h"
#import "UIImageView+WebCache.h"
#import "MoneyString.h"
#import "MYWebService.h"

@interface ApplyTransferredOutVC ()

@end

@implementation ApplyTransferredOutVC
extern NSString *key;
extern NSString *appKey;
extern NSDictionary *userInformation;
extern NSDictionary *accountDic;
NSString *moneyhuachu;  //划出金额


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.bgScrollView setContentSize:CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-120)];
    
    UITapGestureRecognizer *gesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboard)];
    [self.bgScrollView addGestureRecognizer:gesture];
    
    [self.bankImage setImageWithURL:[NSURL URLWithString:[userInformation valueForKey:@"banklog"]]];
    self.lblBankName.text=[userInformation valueForKey:@"bankName"];
    if (![[userInformation valueForKey:@"bankCardNo"] isEqual:[NSNull null]]) {
        NSString *str=[userInformation valueForKey:@"bankCardNo"];
        NSRange a={str.length-4,4};
        int result=[[str substringWithRange:a] intValue];
        self.lbllastCardno.text=[NSString stringWithFormat:@"尾号%d 储蓄卡",result];
    }else
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:nil message:@"无绑定银行卡" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    
    self.txtMoney.text=@"";
    self.lblMoney.text=@"";

    MYWebService *service=[MYWebService new];
    NSString *strQueryAcountInfoService=@"service=queryAcountInfo";
    accountDic = [service getDataSynWithKey:key encryptedString:strQueryAcountInfoService appKey:appKey];
    self.lblBalance.text=[NSString stringWithFormat:@"账户金额:%@元",[accountDic valueForKey:@"availableBalance"]];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction)btnSubmitClick:(UIButton *)sender {
    
    if ([self.lblMoney.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length>0) {
        moneyhuachu=self.txtMoney.text;
        [self presentViewController:[MYTransferredoutVC new] animated:NO completion:nil];
    }else
    {
        NSString *message=@"请输入划出金额";
        NSString *cancel=@"确定";
        ALERTVIEW(message, cancel);
    }
    
}

- (IBAction)btnReturnAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (SCREEN_HEIGHT>480) {
        [self.bgScrollView setContentOffset:CGPointMake(0, 60)];
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    //根据输入金额设置大写金额
    self.lblMoney.text=[MoneyString moneyStringWithDigitStr:self.txtMoney.text];
    if (SCREEN_HEIGHT>480) {
        [self.bgScrollView setContentOffset:CGPointMake(0, 0)];
    }
}
- (void)closeKeyboard
{
    
    [self.view endEditing:YES];
}

- (IBAction)closeKeyboard:(UITextField *)sender {
    //    [self.bgScrollView setContentOffset:CGPointMake(0, 0)];
    [self.view endEditing:YES];
}
#pragma mark-   -----------状态栏底色------
- (UIStatusBarStyle)preferredStatusBarStyle
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
    return NO;
}
@end
